import 'package:flutter/material.dart';

import 'empUtils/EMPImageUtils.dart';

import 'empUtils/EMPString.dart';
import 'empUtils/EMPLayoutUtils.dart';
import 'package:oktoast/oktoast.dart';
import 'package:flutter_constraintlayout/flutter_constraintlayout.dart';

class ExtendCell extends StatefulWidget {

  final String title;       // 成员变量
  final String subTitle;
  final String imgName;
  final String subImgName;

  // ExtendCell 的构造方法  给外界暴露的方法 就像使用Text() 一样
  //快速生成:当我们只定义了上面的成员变量时,会提示报错,
  // 此时选中报错的成员变量然后 option+回车 就自动生成以下构造方法
  const ExtendCell({
    super.key,
    this.title = '',    //@required 类似于ios Protocol @required 表示必传参数
    this.subTitle = '',              //未标记@required为可选参数
    this.imgName = '',
    this.subImgName =''
  });


  @override
  _ExtendCellState createState() => _ExtendCellState();

}

class _ExtendCellState extends State<ExtendCell> {

  @override
  Widget build(BuildContext context) {

    ConstraintId botmeTitle = ConstraintId('botmeTitle');

    return InkWell(
      onTap: () {
        print('InkWell onTap');
        OKToast(child: Text('aaaaa'));
      },
      child: Container(
        padding: EdgeInsets.all(10),  //给整个容器添加一个内边框10,避免贴着屏幕
        height: 54,    // heightForRow
        color: Colors.white,   //cell.backgroundColor
        child: Row(  //整体一个横向布局
          mainAxisAlignment: MainAxisAlignment.spaceBetween, //主轴约束
          children: <Widget>[
            Container(  // left部分：image+label
              child: Row(
                children: [
                  Image(  // UIImageView
                    image: EMPImageUtils.getAssetImage(widget.imgName), //注意：通过widget.ivar 访问内部的成员变量(self.ivar)
                    width:20,
                  ),
                  SizedBox(     //这里元素间的间隔先用SizeBox
                    width: 15,
                  ),
                  Text(widget.title),   //UILabel
                ],
              ),
            ),
            Container(  // right部分：label+image+image
              child: Row(
                children: <Widget>[
                  Text(
                    widget.subTitle != null ? widget.subTitle : '', //注意:给属性赋值是可以写逻辑判断的
                    style: TextStyle(color: Colors.grey),
                  ),
                  EMPString.isEmpty(widget.subImgName) == false ? Container(   //不为null给一个有内容的Container()
                    child: Image(
                      image: EMPImageUtils.getAssetImage(widget.subImgName),
                      width: 15,
                    ),
                    margin: EdgeInsets.only(left: 10,right: 10),
                  ) : Container(),
                  Image(
                    image: EMPImageUtils.getAssetImage('other/setting'),
                    width: 15,
                  )
                ],
              ),
            ),
            Container(
              color: Colors.yellow,
            ).applyConstraint(
              id: botmeTitle,
              size: 15,
              left: parent.left
            ),
            Container(
              color: Colors.red,
            ).applyConstraint(
                size: 15,
                left: botmeTitle.right
            )
          ],
        ),
      )
    );

  }
}



